package org.smile.playground;

import org.objectweb.asm.ClassReader;
import org.smile.day01.Animal;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

public class ZReflection {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
        List<String> names = new ArrayList<>();
        names.add("1");

        List<String> projects = new ArrayList<>();


        Method fAdd = List.class.getMethod("add", Object.class);
        List.class.getAnnotation(lombok.Data.class);
//                      names.getClass().getMethod("");
        fAdd.invoke(projects, "2");

        for (String s : names) {
            System.out.println(s);
        }

        Animal animal = new Animal();
        Field fSize =  Animal.class.getField("eye");
        fSize.set(animal,"qwe");
        System.out.println(animal.eye);
        animal.eye="ss";


        animal.eye="ss";

//        Method[] s = List.class.getMethods();
//        for (Method m : s){
//            m.invoke(names,"");
//        }

        Method speak = Animal.class.getDeclaredMethod("speak");
//        animal.speak();
        Field modifiers = Method.class.getDeclaredField("modifiers");


        modifiers.setAccessible(true);
        modifiers.setInt(speak, Modifier.PUBLIC);

        speak.invoke(animal);
//        animal.speak();
        animal.say();


        List<String> names2 = new ArrayList<>();
        Class<?> asf = Animal.class;

    }

}














